package com.ruoyi.project.system.att.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.att.domain.SysUpAtt;
import com.ruoyi.project.system.att.service.ISysUpAttService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 系统附件Controller
 * 
 * @author yueqiangu
 * @date 2021-02-27
 */
@Controller
@RequestMapping("/system/att")
public class SysUpAttController extends BaseController
{
    private String prefix = "system/att";

    @Autowired
    private ISysUpAttService sysUpAttService;

    @RequiresPermissions("system:att:view")
    @GetMapping()
    public String att()
    {
        return prefix + "/att";
    }

    /**
     * 查询系统附件列表
     */
    @RequiresPermissions("system:att:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUpAtt sysUpAtt)
    {
        startPage();
        List<SysUpAtt> list = sysUpAttService.selectSysUpAttList(sysUpAtt);
        return getDataTable(list);
    }

    /**
     * 导出系统附件列表
     */
    @RequiresPermissions("system:att:export")
    @Log(title = "系统附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysUpAtt sysUpAtt)
    {
        List<SysUpAtt> list = sysUpAttService.selectSysUpAttList(sysUpAtt);
        ExcelUtil<SysUpAtt> util = new ExcelUtil<SysUpAtt>(SysUpAtt.class);
        return util.exportExcel(list, "att");
    }

    /**
     * 新增系统附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统附件
     */
    @RequiresPermissions("system:att:add")
    @Log(title = "系统附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysUpAtt sysUpAtt)
    {
        return toAjax(sysUpAttService.insertSysUpAtt(sysUpAtt));
    }

    /**
     * 修改系统附件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SysUpAtt sysUpAtt = sysUpAttService.selectSysUpAttById(id);
        mmap.put("sysUpAtt", sysUpAtt);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统附件
     */
    @RequiresPermissions("system:att:edit")
    @Log(title = "系统附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysUpAtt sysUpAtt)
    {
        return toAjax(sysUpAttService.updateSysUpAtt(sysUpAtt));
    }

    /**
     * 删除系统附件
     */
    @RequiresPermissions("system:att:remove")
    @Log(title = "系统附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysUpAttService.deleteSysUpAttByIds(ids));
    }
}
